<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Han Ran">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>${title}</title>

    <link href="${homePath}/css/style.css" rel="stylesheet">
    <link href="${homePath}/css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="${homePath}/js/html5shiv.js"></script>
    <script src="${homePath}/js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="login-body">

<div class="container">

    <form class="form-signin"  action="javascrip:void(0)">
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">Sign In</h1>
            <img src="${homePath}/images/login-logo.png" alt=""/>
        </div>

        <div id="login_message" class="alert alert-info fade in" style="display:none">
            <button type="button" class="close close-sm" data-dismiss="alert">
                <i class="fa fa-times"></i>
            </button>
            <strong>登录失败，</strong> 请重新登录！
        </div>

        <div class="login-wrap">
            <input type="text" id="username" class="form-control" placeholder="用户名" autofocus required>
            <input type="password" id="password" class="form-control" placeholder="密码" required>
            <button id="submit" class="btn btn-lg btn-login btn-block" type="submit">
                Login
            </button>
        </div>

    </form>
</div>


<!-- Placed js at the end of the document so the pages load faster -->

<!-- Placed js at the end of the document so the pages load faster -->
<script src="${homePath}/js/jquery-1.10.2.min.js"></script>
<script src="${homePath}/js/bootstrap.min.js"></script>
<script src="${homePath}/js/modernizr.min.js"></script>
<script>
    jQuery(function ($) {
        //使用on代替live和delegate（live由于性能原因已经被废弃，被delegate代替）,新添加到mDiv的button依然会有绑定的事件
        $('#submit').on('click', function (e) {
            var username = $('#username').val();
            var password = $('#password').val();
            if (!$.trim(username) || !$.trim(password)) {
                return;
            }
            $.ajax({
                type: 'POST',
                url: '/admin/login',
                dateType: 'JSON',
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    if (data.success) {
                        window.location.href = "/admin/manager";
                    } else {
                        $('#login_message').show();
                    }
                },
                error: function (e) {
                    $('#login_message').show();
                }
            });
        });
        $('#submit').on('touchstart', function (e) {
            var username = $('#username').val();
            var password = $('#password').val();
            if (!$.trim(username) || !$.trim(password)) {
                return;
            }
            $.ajax({
                type: 'POST',
                url: '/admin/login',
                dateType: 'JSON',
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    if (data.success) {
                        window.location.href = "/admin/manager";
                    } else {
                        $('#login_message').show();
                    }
                },
                error: function (e) {
                    $('#login_message').show();
                }
            });
        });
    });
</script>
</body>
</html>
